package com.example.blew.omp.system.model;

import com.example.blew.omp.system.config.ReturnEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class ReturnModel<T> implements Serializable {
    /**
     * 响应状态
     *
     * @see
     */
    private String code;

    /**
     * 响应信息
     *
     * @see
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;

    /***
     * 成功标识
     */
    private boolean success;

    private ReturnModel() {

    }

    private ReturnModel(String code, String msg) {
        this.code = code;
        this.message = msg;
    }

    private ReturnModel(String code, String msg, T data) {
        this.code = code;
        this.message = msg;
        this.data = data;
    }

    public static <T> ReturnModel<T> newFailureInstance() {
        ReturnModel<T> returnModel = new ReturnModel(ReturnEnum.E000001.getCode(), ReturnEnum.E000001.getMessage());
        returnModel.setSuccess(false);
        return returnModel;
    }


    public static <T> ReturnModel<T> newSuccessInstance(){
        ReturnModel<T> returnModel = new ReturnModel(ReturnEnum.S000000.getCode(), ReturnEnum.S000000.getMessage());
        returnModel.setSuccess(true);
        return returnModel;

    }

    public static <T> ReturnModel<T> newSuccessInstance(T t){
        ReturnModel<T> returnModel = new ReturnModel(ReturnEnum.S000000.getCode(), ReturnEnum.S000000.getMessage());
        returnModel.setSuccess(true);
        returnModel.setData(t);
        return returnModel;

    }
}
